function packDataById(...ids) {
    const data = {};
    ids.forEach(id => {
        const element = document.getElementById(id);
        if (element) {
            data[id] = element.value;
        }
    });
    return data;
}

async function fetchPost(url, data) {
    try {
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data),
        });

        if (response.redirected) {
            window.location.href = response.url;
            return;
        }

        const json = await response.json();

        if (!json.hasOwnProperty('msg')) {
            json.msg = '';
        }

        return json;
    } catch (error) {
        return { msg: 'fetchPost error' };
    }
}
